package com.qf.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.core.dto.PageDto;
import com.qf.core.vo.PageResult;
import com.qf.product.dto.Vo;
import com.qf.product.entity.Product;
import com.qf.product.mapper.ProductMapper;
import com.qf.product.service.ProductService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 产品表 服务实现类
 * </p>
 *
 * @author yxh
 * @since 2023-10-26
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Override
    public PageResult<Product> findPage(PageDto<Vo> pageDto) {
        IPage<Product> page = new Page<>(pageDto.getNow(), pageDto.getSize());
//        Product where = pageDto.getWhere();
//
//        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
//        if(!StringUtils.isEmpty(where.getName())){
//            queryWrapper.lambda().like(Product::getName,where.getName());
//        }
//        if(!StringUtils.isEmpty(where.getUsername())){
//            queryWrapper.lambda().like(Product::getUsername,where.getUsername());
//        }
//        if(!StringUtils.isEmpty(where.getProductKey())){
//            queryWrapper.lambda().like(Product::getProductKey,where.getProductKey());
//        }
//        IPage<Product> pageInfo = this.baseMapper.selectPage(page, queryWrapper);

        IPage<Product> pageInfo = this.baseMapper.selectAll(page,pageDto.getWhere());
        PageResult<Product> pageResult = new PageResult<>();
        pageResult.setPages(pageInfo.getPages());
        pageResult.setList(pageInfo.getRecords());
        pageResult.setTotal(pageInfo.getTotal());
        return pageResult;
    }
}
